var locked;
var old_modcat = old_id = false;
function doOnload()
{
	var layer;
	if(layer = document.getElementById('LOx_layer'))
	{
		var right,left = getLeft(1)+1;
		layer.style.left = left;
		layer.style.top = 0;
		document.getElementById('LOx_table').left = left;
		
		for(i=2;column = document.getElementById('LOx'+i);i++)
		{
			right = getLeft(i);
			if(i==2)
				subtract = 10;
			else
				subtract = 12;
			document.getElementById('LO_col'+(i-1)).width = right-left-subtract;
			left = right;
		}
		document.getElementById('LO_col'+(i-2)).width = left-getLeft(i-2)-2;
		total_width = getLeft(i-1)-getLeft(1) + 10;
		document.getElementById('LOx_table').width = total_width;
		if(navigator.userAgent.indexOf('Safari')==-1)
			window.setInterval('doOnscroll()',50);
		else
			window.onscroll = doOnscroll;
		window.onresize = doOnresize;
	}

	if(layer = document.getElementById('LOy_layer'))
	{
		var bottom,top = getTop(1)-2;
		var left = getLeft(1)
		layer.style.left = left;
		layer.style.top = top;
		document.getElementById('LOy_table').left = left;
		document.getElementById('LOy_table').top = top;
		
		for(i=1;row = document.getElementById('LOy_row'+i);i++)
		{
			bottom = getTop(i);
			maxHeight = row.cells[1].offsetHeight;
			for(j=1;j<row.cells.length;j++)
			{
				if(maxHeight<row.cells[j].offsetHeight)
					maxHeight = row.cells[j].offsetHeight;
			}
			//document.getElementById('LO_row'+(i-1)).height = bottom-top-2;
			document.getElementById('LOy_floatingrow'+i).height = maxHeight;
			top = bottom;
		}
		document.getElementById('LOy_table').width = getLeft(2)-getLeft(1);
		if(navigator.userAgent.indexOf('Safari')==-1)
			window.setInterval('doOnscroll()',50);
		else
			window.onscroll = doOnscroll;
	}
	window.onresize = doOnresize;
	positionMenus();
	putFocus();
}

function doOnresize()
{
	doOnload();
	doOnscroll();
}

var old_modcat = false;
var opened = false;
function doOnBodyClick()
{
	if(old_modcat!=false && opened==false)
	{
		document.getElementById("menu_hidden"+old_modcat).style.visibility = "hidden";
		document.getElementById("button_"+old_modcat).style.backgroundColor = "transparent";
		document.getElementById("button_"+old_modcat).style.color = '#000000';
		old_modcat = false;
	}
	opened = false;
}

function doOnscroll()
{
	var layer;
	if(layer = document.getElementById("LOx_layer"))
	{
		var pY = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset); 
		if(pY > getListTop())
			layer.style.visibility = "visible";
		else
			layer.style.visibility = "hidden"; 
		if(pY)
			layer.style.top = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset);
	}
	
	if(layer = document.getElementById("LOy_layer"))
	{
		var pX = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset); 
		if(pX > 25)
			layer.style.visibility = "visible";
		else
			layer.style.visibility = "hidden"; 
		if(pX)
			layer.style.left = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
	}
}

function getLeft(column_number)
{
	var x = 0;
	if(document.layers)
		x = document.layers['LOx'+column_number].pageX;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all['LOx'+column_number] : document.getElementById('LOx'+column_number);
		while(cell)
		{
			x += cell.offsetLeft;
			cell = cell.offsetParent;
		}
	}
	return x-8;
}

function getTop(row_number)
{
	var y = 0;
	if(document.layers)
		y = document.layers['LOy'+row_number].pageY;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all['LOy'+row_number] : document.getElementById('LOy'+row_number);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y-6;
}

function getListTop()
{
	var y = 0;
	if(document.layers)
		y = document.layers['LOx1'].pageY;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all['LOx1'] : document.getElementById('LOx1');
		while(cell)
		{
		  y += cell.offsetTop;
		  cell = cell.offsetParent;
		}
	}
	return y;
}

function getListBottom(column_number)
{
	var y = 0;
	if(document.layers)
		y = document.layers['LOx'+column_number].pageY;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all['LOx'+column_number] : document.getElementById('LOx'+column_number);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y-6;
}

var runPutFocus = true;
function putFocus()
{
	var i,o;
	if(document.forms.length > 0 && runPutFocus==true)
	{
		for(o=0;o<document.forms.length;o++)
		{
			for(i=0;i<document.forms[o].elements.length;i++)
			{
				if(document.forms[o].elements[i].type=='text' && document.forms[o].elements[i].name!='LO_search')
				{
					document.forms[o].elements[i].focus();
					// we don't want this function to do anything if it's being called a second time (for instance if a hidden field is clicked)
					runPutFocus = false;
					return;
				}
			}
		}
	}
}

function addHTML(html,id,replace)
{
	if(locked!=false)
	{
		if(replace==true)
			document.getElementById(id).innerHTML = html;
		else	
			document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + html;
	}
}

function changeHTML(show,hide)
{
	for(key in show)
		document.getElementById(key).innerHTML = document.getElementById(show[key]).innerHTML;
	for(i=0;i<hide.length;i++)
		document.getElementById(hide[i]).innerHTML = '';
}

function checkAll(form,value,name_like)
{
	if(value==true)
		checked = true;
	else
		checked = false;
	
	for(i=0;i<form.elements.length;i++)
	{
		if(form.elements[i].type=='checkbox' && form.elements[i].name!='controller' && form.elements[i].name.substr(0,name_like.length)==name_like)
			form.elements[i].checked = checked;
	}
}

function openMenu(modcat)
{
	document.getElementById("menu_"+modcat).display = 'block';
	if(old_modcat!=false)
		document.getElementById("menu_"+old_modcat).display = 'none';
	//document.getElementById("modcat_input").value=modcat;	
	if(old_modcat==modcat)
		old_modcat = false;
	else
		old_modcat = modcat;
}

function getXPos(id)
{
	var x = 0;
	if(document.layers)
		x = document.layers[id].pageX;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all[id] : document.getElementById(id);
		while(cell)
		{
			x += cell.offsetLeft;
			cell = cell.offsetParent;
		}
	}
	return x;
}

function replaceAll(haystack,needle,replacement)
{
	haystack = haystack.replace(needle,replacement);
	if(haystack.match(needle))
		haystack = replaceAll(haystack,needle,replacement);
	return haystack;
}

function switchMenu(id)
{
	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(id+'_arrow').src = 'assets/arrow_down.gif';		
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(id+'_arrow').src = 'assets/arrow_right.gif';		
	}
	positionMenus();
}

var single_quote = "'";
var double_quote = '``';